package cn.z2huo.knowledge.basic.method.variableparamlist;

import java.util.Arrays;
import java.util.List;

/**
 * <p>Arrays.asList 方法测试
 *
 * @author z2huo
 */
class ArraysAsListTest {

    /**
     * 基础数据类型的数组不会自动装箱为包装类型的数组
     */
    public void intTest() {
        int[] array = {2, 1, 4, 3};
        List list = Arrays.asList(array);
        System.out.println(list);
        System.out.println(list.get(0).getClass());
    }

    public void integerTest() {
        Integer[] integerArray = new Integer[2];
        integerArray[0] = 2;
        integerArray[1] = 4;
        List<Integer> list = Arrays.asList(integerArray);
        System.out.println(list);
        System.out.println(list.get(0).getClass());
    }

    public void integerTest2() {
        Integer[] integerArray = {2, 4};

        List<Integer> list = Arrays.asList(integerArray);
        System.out.println(list);
        System.out.println(list.get(0).getClass());
    }

    public void stringTest() {
        String[] stringArray = {"aa", "bb"};

        List<String> list = Arrays.asList(stringArray);
        System.out.println(list);
        System.out.println(list.get(0).getClass());
    }

    public void intArrayAsListTest() {
        List list = Arrays.asList(1, 2);

        System.out.println(list);
        System.out.println(list.get(0).getClass());
    }

    public static void main(String[] args) {
        ArraysAsListTest arraysAsListTest = new ArraysAsListTest();
        arraysAsListTest.intTest();
        System.out.println();
        arraysAsListTest.integerTest();
        System.out.println();
        arraysAsListTest.integerTest2();
        System.out.println();
        arraysAsListTest.stringTest();
        System.out.println();
        arraysAsListTest.intArrayAsListTest();
    }

}
